﻿// See https://aka.ms/new-console-template for more information
using System;
using System.Text.Json;
using System.Net.Http;
using System.Threading.Tasks;
using Line;

Console.WriteLine(string.Join("", Enumerable.Repeat("-", 60).ToArray()));

async Task<LineMode> GetLine()
{
    using var client = new HttpClient();
    using var response = await client.GetAsync($"https://v1.hitokoto.cn/");
    using var content = response.Content;
    var result = await content.ReadAsStringAsync();
    LineMode mode = JsonSerializer.Deserialize<LineMode>(result);
    return mode;
}
string line = "一无所获";
LineMode mode = await GetLine();
if (mode != null && !string.IsNullOrEmpty(mode.hitokoto))
{
    line = mode.hitokoto + "\r\n" + $"\t\t—— {mode.from}[{mode.from_who}]";
}

Console.WriteLine(line);
Console.WriteLine(string.Join("", Enumerable.Repeat("-", 60).ToArray()));